package com.kyzh.core.dialog

import android.annotation.SuppressLint
import android.app.Activity
import android.view.LayoutInflater
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.databinding.DataBindingUtil
import com.kyzh.core.R
import com.kyzh.core.databinding.DialogExchangeBinding


private var exchangeDialog:AlertDialog?=null

fun Activity.showExchangeDialog(title: String,point:String,listener:()->Unit){
    exchangeDialog = AlertDialog.Builder(this, R.style.kyzhGuestLoginDialog)
            .setView(getView(title,point,listener))
            .create()

    exchangeDialog?.show()
}
@SuppressLint("ClickableViewAccessibility")
private fun Activity.getView(title: String, point: String,listener:()->Unit):View{
    val binding = DataBindingUtil.inflate<DialogExchangeBinding>(LayoutInflater.from(this),R.layout.dialog_exchange,null,false)
    binding.tvTitle.text = title
    binding.btGet.text = String.format(getString(R.string.exchangeButtonText),point)
    binding.btGet.setOnClickListener {
        listener()
        exchangeDialog?.dismiss()
    }
    binding.cancel.setOnClickListener {
        exchangeDialog?.dismiss()
    }
    return binding.root
}